package ModelLayer;
import java.util.HashMap;
import java.util.ArrayList;

/**
 * The LoanCollection class contains Loans in a HashMap.
 * 
 * @author (group 1(A)) 
 * @version (14/4-2011)
 */
public class LoanCollection
{
    // instance variables - replace the example below with your own
    private ArrayList<Loan> loan;
    private HashMap<Person, ArrayList<Loan>> loans;
    //private static LoanCollection instance = null;
    
    /**
     * Constructor for objects of class LoanCollection
     */
    public LoanCollection()
    {
        // initialise instance variables
        loans = new HashMap<Person, ArrayList<Loan>>();
        loan = new ArrayList<Loan>();
    }

   /**
     * Add a Loan to LoanCollection
     * @param p takes a parameter of type loan
     * @param l ArrayList that stores objects of type loan
     */
    public void addLoans(Person p, ArrayList<Loan> l)
    {
       //loan.add(l);
       loans.put (p, l);
    }
    
    /**
     * Finds a loan
     * @param p An object of type Person
     * @param id Id of the loan
     * @return Returns an object of type loan
     */
    public Loan findLoan(Person p, int id)
    {
        ArrayList<Loan> myLoans = loans.get(p);
        Boolean found = false;
        int index = 0;
        Loan l = null;
        while(index < myLoans.size() && !found)
        {
            if(myLoans.get(index).getId() == id)
            {
                found = true;
                l = myLoans.get(index);  
            }
            index++;
        }
        if(!found)
        {
            System.out.println("No loans found!");
        }
        return l;
    }
    
    /**
     * Not implemented
     */
    public void updateLoan()
    {
    }
    
    /**
     * Not implemented
     */
    public void deleteLoan()
    {
    }
    
    /**
     * Not implemented
     */
    public void listAllLoan()
    {
    }
    //public static LoanCollection getInstance()
    //{
     //   if(instance == null)
       // {
        //    instance = new LoanCollection();
        //}
        //return instance;
    //}
    
   
}
